__author__  = 'Tom-Wilkin Martinussen <tom@oberon.no>'

from AccessControl import ClassSecurityInfo, AuthEncoding

from zope.interface import implements

from Products.CMFCore import permissions
from AccessControl import getSecurityManager, ClassSecurityInfo
from Products.Archetypes.interfaces.orderedfolder import IOrderedFolder
from Products.ATContentTypes.atct import ATFolder, ATFolderSchema
from Products.ATContentTypes.atct import ATCTContent, ATContentTypeSchema
from Products.ATContentTypes.content.document import ATDocument

from config import *
from Products.ATContentTypes.configuration import zconf
from Products.Archetypes.public import registerType
from Products.Archetypes.public import DisplayList
from Products.CMFCore.utils import getToolByName


try:
	from Products.LinguaPlone.public import *
except ImportError:
	# No multilingual support
	from Products.Archetypes.public import *

schema  = ATFolderSchema.copy() + Schema ((

        ComputedField('estimated_hours',
              index="FieldIndex:brains",
              expression="context.scripts.getAllProjectTasks(context)['estimated']",
              visible=False
        ),		  

        ComputedField('used_hours',
              index="FieldIndex:brains",
              expression="context.scripts.getAllProjectTasks(context)['used']",
              visible=False
        ),
))

schema['description'].widget.visible = True
schema['relatedItems'].widget.visible = True
schema.moveField('relatedItems', pos='bottom')

class TaskExtrafolder(ATFolder):
#class Taskfolder(ATCTContent):
    """ A task folder can contain several sub tasks """
    
    schema = schema
    
    meta_type = archetype_name = portal_type = 'TaskExtrafolder'
    content_icon = 'taskextrafolder.gif'
#    _at_rename_after_creation = True
    global_allow = 0
    immediate_view = 'foldertaskextraprogress_view'
    default_view = 'foldertasextrakprogress_view'

    filter_content_types = 1
    allowed_content_types = ('TaskExtra', 'TaskExtrafolder')

    
    actions = ({
        'id': 'view',
        'name': 'View',
        'action': 'string:${object_url}/foldertaskextraprogress_view',
        'permissions': (permissions.View,)
        },{
        'id': 'edit',
        'name': 'Edit',
        'action': 'string:${object_url}/base_edit',
        'permissions': (permissions.ViewManagementScreens,)
        },{
        'id': 'metadata',
        'name': 'Properties',
        'action': 'string:${object_url}/base_metadata',
        'permissions': (permissions.ViewManagementScreens,)
        },)
        

##
# Folder contents actionen ville ikke overstyres herfra.
# Har derfor endret tillatelse paa denne actionene via ZMI.
# Dette maa enten fikses her, eller ZMI settingen maa inn i Install.py
#
#        {
#        'id': 'folderContents',
#        'name': 'Contents',
#        'action': 'string:${object_url}/folder_contents',
#        'permissions': (CMFCorePermissions.ViewManagementScreens,)
#        },)
        
registerType(TaskExtrafolder, PROJECTNAME)
